bitkeeper revision 1.1420 (4288c742JYmWjAz3bZlZhafhzuQ73w)
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Mon, 16 May 2005 16:16:02 +0000 (16:16 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Mon, 16 May 2005 16:16:02 +0000 (16:16 +0000)
Vifctl.py:
  Pass script output through logger.
process.py:
  os.system() replacement which outputs through the logger
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
.rootkeys
tools/python/xen/util/process.py [new file with mode: 0644]
tools/python/xen/xend/Vifctl.py

index c4b0af0cad016c25a948bfc7c3895933dd6aaf69..597af41af34a96c93379a40439c89751a2c6342d 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 4055ee4dwy4l0MghZosxoiu6zmhc9Q tools/python/xen/util/console_client.py
 40c9c468IienauFHQ_xJIcqnPJ8giQ tools/python/xen/util/ip.py
 41dde8b0yuJX-S79w4xJKxBQ-Mhp1A tools/python/xen/util/memmap.py
+4288c6fcB1kUAqX0gzU85GGxmamS4Q tools/python/xen/util/process.py
 4059c6a0pnxhG8hwSOivXybbGOwuXw tools/python/xen/util/tempfile.py
 4267a9b16u4IEPhjRryesk6A17sobA tools/python/xen/web/SrvBase.py
 4267a9b1FfCUjW7m9anLERcx9lwhJg tools/python/xen/web/SrvDir.py
diff --git a/tools/python/xen/util/process.py b/tools/python/xen/util/process.py
new file mode 100644 (file)
index 0000000..f6aac50
--- /dev/null
@@ -0,0 +1,31 @@
+# Copyright (C) 2005 Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
+
+# os.system() replacement which outputs through the logger
+
+import popen2
+import select
+
+from xen.xend.XendLogging import log
+
+def system(cmd):
+    # split after first space, then grab last component of path
+    cmdname = "[%s] " % cmd.split()[0].split('/')[-1]
+    # run command and grab stdin, stdout and stderr
+    cout, cin, cerr = popen2.popen3(cmd)
+    # close stdin to get command to terminate if it waits for input
+    cin.close()
+    # wait for output and process
+    p = select.poll()
+    p.register(cout)
+    p.register(cerr)
+    while True:
+        r = p.poll()
+        for (fd, event) in r:
+            if event == select.POLLHUP:
+                return
+            if fd == cout.fileno():
+                l = cout.readline()
+                log.info(cmdname + l.rstrip())
+            if fd == cerr.fileno():
+                l = cerr.readline()
+                log.error(cmdname + l.rstrip())
index fe33ecbc712f7fcdd23cfdd15dc8919692eeacca..d26f78d7a03a145a3b6bc3662a08eb220039cc24 100644 (file)
@@ -3,6 +3,7 @@
 import os
 import os.path
 import sys
+import xen.util.process
 
 from xen.xend import XendRoot
 xroot = XendRoot.instance()
@@ -35,7 +36,7 @@ def network(op, script=None, bridge=None, antispoof=None):
     else:
         args.append("antispoof=no")
     args = ' '.join(args)
-    os.system(script + ' ' + args)
+    xen.util.process.system(script + ' ' + args)
 
 def set_vif_name(vif_old, vif_new):
     if vif_old == vif_new: